package xc.doughnut.demo;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ReptilesDemo {
    public static void main(String[] args) throws Exception {

        // 创建一个url对象
        URL url = new URL("http://szb.chinalxnet.com/pc/cont/202207/26/content_75052.html");
        // 保证网络畅通
        URLConnection urlConnection = url.openConnection();
        // 读取网络数据
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

        String line;
        // 身份证正则
        String regex = "[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]";
        Pattern compile = Pattern.compile(regex);
        while ((line = bufferedReader.readLine()) != null) {
            // 按照正则规则匹配
            Matcher matcher = compile.matcher(line);
            while (matcher.find()) {
                System.out.println(matcher.group());
            }
        }
        bufferedReader.close();
    }
}
